/*
 * @(#)IndexAction.java $version 2011. 10. 14
 * 
 * Copyright 2011 NHN Corp. All rights Reserved.
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.hangame.mbl.action;

import java.util.List;

import javax.servlet.http.Cookie;

import org.apache.commons.lang.StringUtils;

import com.hangame.mbl.constant.CommonConst;
import com.hangame.mbl.model.Banner;
import com.hangame.mbl.util.CookieHelper;
import com.nhncorp.lucy.common.data.DataHandlerFactory;
import com.nhncorp.lucy.web.context.ServiceContext;

// TODO: Auto-generated Javadoc
/**
 * The Class IndexAction.
 *
 * @author NHN
 */
public class IndexAction extends SmartCommonBaseAction {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -4409896918550473123L;
	private static final String COOKIE_DOMAIN = StringUtils.substringAfter(DataHandlerFactory.getDataHandler().get("url/smart"), "//");
	/**
	 * Inits the.
	 * 
	 * @return the string
	 * @throws Exception the exception
	 * @return
	 * @see com.hangame.mbl.action.SmartCommonBaseAction#init()
	 */
	@Override
	public String init() throws Exception {
		setHasNotiWithoutRecoGame(true);
		
		return super.init();
	}

	/* (non-Javadoc)
	 * @see com.hangame.mbl.action.SmartPortalAction#execute()
	 */
	@Override
	public String execute() throws Exception {
		Cookie tookenCookie = ServiceContext.getCookie("IS_MOBILE_REDIRECT");
		if (tookenCookie != null) {
			setAttribute("IS_REDIRECTED_FROM_MOBILE", true);
			ServiceContext.setCookie("IS_MOBILE_REDIRECT", "", 0, COOKIE_DOMAIN);
		} else {
			setAttribute("IS_REDIRECTED_FROM_MOBILE", false);
		}
		
		List<Banner> bannerHomeList = bannerBO.getBannerList(CommonConst.BANNER_LOC_HOME);
		setAttribute("bannerHomeList", bannerHomeList);
		setLatestNoticeList(); //공지3개
		return SUCCESS;
	}

	public String mobile() throws Exception {
		String token = CookieHelper.createCookieValueString("IS_MOBILE_REDIRECT", "TRUE");
		ServiceContext.setCookie("IS_MOBILE_REDIRECT", token, 60, COOKIE_DOMAIN);
		
		return "mobile";
	}
}
